package cn.huiyunche.base.service.interfaces.impl;

import cn.huiyunche.base.service.interfaces.ComplexQueryService;
import cn.huiyunche.base.service.vo.Result;
import cn.huiyunche.tools.basic.exceptions.BusinessException;
import org.apache.commons.lang3.RandomUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;

@Service

public class ComplexQueryServiceImpl implements ComplexQueryService {

    private static final Logger LOGGER = LoggerFactory.getLogger(ComplexQueryServiceImpl.class);

    public Result<Map<String, Integer>> selectOnlineInfo() {
        Result<Map<String, Integer>> result = new Result<Map<String, Integer>>(true, "查询成功！");
        Map<String, Integer> map = new HashMap<String, Integer>();
        try {
            Calendar now = Calendar.getInstance();
            int year = now.get(Calendar.YEAR);
            int month = now.get(Calendar.MONTH);
            int date = now.get(Calendar.DATE);
            Calendar startTime = new GregorianCalendar(year, month, date, 6, 0, 0);
            Calendar endTime = new GregorianCalendar(year, month, date, 20, 0, 0);
            if (now.after(startTime) && now.before(endTime)) {
                map.put("driver", RandomUtils.nextInt(5500, 5700));
                map.put("order", RandomUtils.nextInt(5000, 7000));
                result.setData(map);
            } else {
                map.put("driver", RandomUtils.nextInt(2200, 2300));
                map.put("order", RandomUtils.nextInt(2000, 5000));
                result.setData(map);
            }
            return result;
        } catch (Exception e) {
            LOGGER.error("ComplexQueryServiceImpl.selectOnlineInfo error : {}", e);
            throw new BusinessException("查询失败！");
        }
    }

}
